Gradient Boost

Before moving forward with the to-do list, let’s throw a Random Forest to it.

Gradient boost

For many reasons, Random Forest is usually a very good baseline model. In this particular case I started with the polynomial OLS as baseline model, just because it was so evident from the correlations that the relationship between temperature and consumption follows a polynomial shape. But let’s go back to a beloved RF.

Model Cards provide a framework for transparent, responsible reporting. 
 Use the vetiver `.qmd` Quarto template as a place to start, 
 with vetiver.model_card()
Writing pin:
Name: 'wd-gb'
Version: 20250111T085512Z-6e386
<vetiver.vetiver_model.VetiverModel at 0x7f112be6cdc0>

Metrics

Single Split CV
train test test train
MAE - Mean Absolute Error 1.367836 2.018104 2.149734 1.248390
MSE - Mean Squared Error 3.611510 15.843664 10.354526 2.923534
RMSE - Root Mean Squared Error 1.900397 3.980410 2.963316 1.709055
R2 - Coefficient of Determination 0.962304 0.815525 -3.226769 0.970113
MAPE - Mean Absolute Percentage Error 0.126245 0.188933 0.331322 0.106836
EVS - Explained Variance Score 0.962304 0.820174 -0.477653 0.970113
MeAE - Median Absolute Error 0.949191 1.244464 1.663562 0.937973
D2 - D2 Absolute Error Score 0.809482 0.686323 -0.762466 0.823063
Pinball - Mean Pinball Loss 0.683918 1.009052 1.074867 0.624195

Scatter plot matrix

Observed vs. Predicted and Residuals vs. Predicted

Check for …

check the residuals to assess the goodness of fit.

  • white noise or is there a pattern?
  • heteroscedasticity?
  • non-linearity?

Normality of Residuals:

Check for …

  • Are residuals normally distributed?

Leverage

Scale-Location plot

Residuals Autocorrelation Plot

Residuals vs Time

Again, overfits a lot.

Parameter: param_model__learning_rate

Parameter: param_model__max_depth

Parameter: param_model__min_samples_leaf

Parameter: param_model__min_samples_split

Parameter: param_model__n_estimators

Parameter: param_model__subsample

Parameter: param_vars__columns

Best model

{'model__learning_rate': 0.1,
 'model__max_depth': 5,
 'model__min_samples_leaf': 5,
 'model__min_samples_split': 48,
 'model__n_estimators': 60,
 'model__subsample': 1,
 'vars__columns': ['rf_tu_mean', 'vp_std_mean']}
Pipeline(steps=[('vars', ColumnSelector(columns=['rf_tu_mean', 'vp_std_mean'])),
                ('model',
                 GradientBoostingRegressor(max_depth=5, min_samples_leaf=5,
                                           min_samples_split=48,
                                           n_estimators=60, random_state=7,
                                           subsample=1))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

Metrics

Single Split CV
train test test train
MAE - Mean Absolute Error 1.501939 2.004927 2.149701 1.497526
MSE - Mean Squared Error 4.772564 16.345725 8.340059 4.882049
RMSE - Root Mean Squared Error 2.184620 4.042985 2.775528 2.207723
R2 - Coefficient of Determination 0.950186 0.809679 -3.222706 0.950079
MAPE - Mean Absolute Percentage Error 0.132512 0.192896 0.349519 0.118405
EVS - Explained Variance Score 0.950186 0.816446 -0.358865 0.950079
MeAE - Median Absolute Error 0.973946 1.167454 1.674513 1.011380
D2 - D2 Absolute Error Score 0.790804 0.688371 -0.813219 0.787657
Pinball - Mean Pinball Loss 0.750969 1.002464 1.074850 0.748763

Scatter plot matrix

Observed vs. Predicted and Residuals vs. Predicted

Check for …

check the residuals to assess the goodness of fit.

  • white noise or is there a pattern?
  • heteroscedasticity?
  • non-linearity?

Normality of Residuals:

Check for …

  • Are residuals normally distributed?

Leverage

Scale-Location plot

Residuals Autocorrelation Plot

Residuals vs Time

Compare vanilla vs. tuned

Metrics

Single split

Metrics based on the test set of the single split

Cross validation

Predictions, residuals, observed

next

Time vs. Predicted and Observed

Time vs. Residuals

Model details

Pipeline(steps=[('vars',
                 ColumnSelector(columns=['tt_tu_mean', 'rf_tu_mean', 'td_mean',
                                         'vp_std_mean', 'tf_std_mean'])),
                ('model', GradientBoostingRegressor(random_state=7))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
Pipeline(steps=[('vars', ColumnSelector(columns=['rf_tu_mean', 'vp_std_mean'])),
                ('model',
                 GradientBoostingRegressor(max_depth=5, min_samples_leaf=5,
                                           min_samples_split=48,
                                           n_estimators=60, random_state=7,
                                           subsample=1))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

TODOs